//
//  ChangePassController.m
//  FengyuanXS
//
//  Created by 王冬 on 2020/7/27.
//  Copyright © 2020 王冬. All rights reserved.
//

#import "ChangePassController.h"
#import "LoginViewController.h"
#import "RootViewController.h"
@interface ChangePassController ()
@property (weak, nonatomic) IBOutlet UITextField *passText;
@property (weak, nonatomic) IBOutlet UITextField *xinPassText;
@property (weak, nonatomic) IBOutlet UITextField *xinPassWordText;
@property (weak, nonatomic) IBOutlet UITextField *phoneText;
@property (weak, nonatomic) IBOutlet UITextField *codeText;
@property (weak, nonatomic) IBOutlet UIButton *codeBtn;

- (IBAction)codeBtn:(UIButton *)sender;
@end

@implementation ChangePassController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"修改密码";
    self.phoneText.text = [TokenManager getToken];
}



- (IBAction)codeBtn:(UIButton *)sender {
    [[ApiManager ShardInstance]codeuserID:[TokenManager getUserId] mobile:self.phoneText.text type:@"0" resultBlock:^(NSDictionary *data, NSError *error) {
        BaseModel *model = [BaseModel mj_objectWithKeyValues:data];
        if (model.code == 1) {
            [AuthCodeManager getValidCode:sender];
            [[ToastManager shardInstance]showToast:model.msg];
        }
        
    }];
    
}

- (IBAction)commitBtn:(BoardButton *)sender {
    
    if ([self.xinPassText.text isEqualToString:self.xinPassWordText.text]) {
        [[ApiManager ShardInstance]editPassid:[TokenManager getUserId] old_pass:self.passText.text new_pass:self.xinPassText.text captcha:self.codeText.text resultBlock:^(NSDictionary *data, NSError *error) {
            BaseModel *model = [BaseModel mj_objectWithKeyValues:data];
            if (model.code == 1) {
                [TokenManager removeUserId];
                [TokenManager removeToken];
                [self quitApp];
            }
            [[ToastManager shardInstance]showToast:model.msg];
            
        }];
    }else{
        
        [[ToastManager shardInstance]showToast:@"两次密码不一致"];
    }
    
}

-(void)quitApp{
    
    
    
    LoginViewController *loginVC = [LoginViewController loadStroyboard:[LoginViewController new]];
    
    UINavigationController * nav = [[RootViewController alloc] initWithRootViewController:loginVC];
    nav.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:nav animated:YES completion:nil];
    
}

@end
